import { defHttp } from '@/utils/http/axios';
import { BasicFetchResult } from '@/api/model/baseModel'
import { RoleModel, RoleParams, GetRoleListParams, PermissionModule, Permission } from './model/role';

import { ErrorMessageMode } from '#/axios';

export function getRoleList(params: GetRoleListParams, mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<RoleModel>>(
    {
      url: '/account/roles',
      params,
    },
    {
      errorMessageMode: mode
    }
  );
}

export function getPermissionModuleList(mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<PermissionModule>>(
    {
      url: '/account/permissions/modules',
    },
    {
      errorMessageMode: mode
    }
  );
}

export function getPermissionList(mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<Permission>>(
    {
      url: '/account/permissions/list',
    },
    {
      errorMessageMode: mode
    }
  );
}

export function createRole(params: RoleParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post<RoleModel>(
    {
      url: '/account/roles',
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function editRole(id: number, params: RoleParams, mode: ErrorMessageMode = 'message') {
  return defHttp.patch<RoleModel>(
    {
      url: `/account/roles/${id}`,
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function deleteRole(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.delete(
    {
      url: `/account/roles/${id}`
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}
